package sql;



import java.sql.*;

public class Test1 {
    public static void main(String[] args) {
        Connection connection=null;
        Statement statement=null;
        ResultSet resultSet=null;

        try {
            //1.加载数据库驱动
            Class.forName("com.mysql.cj.jdbc.Driver");
            //2.获取数据库连接
            connection = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/test_csdn?useUnicode=true&characterEncoding=UTF-8&useSSL=false" +
                        "root" +
                        "508065");
            //3.创建Statement对象
            statement=connection.createStatement();
            //4。定义sql语句
            String sql="select * from student where math>60 and chinese >65";
            //5.执行sql语句
            resultSet=statement.executeQuery(sql);
            //6.遍历结果
            while(resultSet.next()){
                long id=resultSet.getLong(1);
                String name=resultSet.getString(2);
                float chinese=resultSet.getFloat(3);
                float english=resultSet.getFloat(4);
                float math=resultSet.getFloat(5);
                System.out.println(id+"\t"+name+"\t"+chinese+"\t"+english+"\t"+math+"\t");
            }


        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        } finally {

        }


    }
}
